package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import com.fr.report.script.core.FunctionHelper;

public class FLOOR extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 1)
      return Primitive.ERROR_NAME;
    if (paramArrayOfObject.length == 1)
    {
      localObject1 = paramArrayOfObject[0];
      if (!(localObject1 instanceof Number))
        break label333;
      return FunctionHelper.parsePrimitiveDouble(Math.floor(((Number)localObject1).doubleValue()));
    }
    Object localObject1 = paramArrayOfObject[0];
    Object localObject2 = paramArrayOfObject[1];
    if ((localObject1 instanceof Number) && (localObject2 instanceof Number))
    {
      double d1 = ((Number)localObject1).doubleValue();
      double d2 = ((Number)localObject2).doubleValue();
      if (d1 * d2 < 0.0D)
        return Primitive.ERROR_VALUE;
      if (d1 >= 0.0D)
      {
        if (d1 == 0.0D)
          return new Integer(0);
        if (d2 == 0.0D)
          return Primitive.ERROR_VALUE;
        if (d2 > d1)
          return new Integer(0);
        d3 = 1.0D;
        d3 = Math.round(d1 / d2) + 3L;
        l = ()d3;
        while (l >= 0L)
        {
          if (d2 * l <= d1)
          {
            d3 = d2 * l;
            break;
          }
          l -= 1L;
        }
        return FunctionHelper.parsePrimitiveDouble(d3);
      }
      if ((d2 == 0.0D) || (d1 == 0.0D))
        return new Integer(0);
      if (d2 == 0.0D)
        return Primitive.ERROR_VALUE;
      if (d2 < d1)
        return new Integer(0);
      double d3 = 1.0D;
      d3 = Math.round(d1 / d2) + 3L;
      long l = ()d3;
      while (l >= 0L)
      {
        if (d2 * l >= d1)
        {
          d3 = d2 * l;
          break;
        }
        l -= 1L;
      }
      return FunctionHelper.parsePrimitiveDouble(d3);
    }
    label333: return Primitive.ERROR_NAME;
  }

  public Function.Type getType()
  {
    return Function.MATH;
  }

  public String getCN()
  {
    return "FLOOR(number,significance): 将参数number沿绝对值减小的方向去尾舍入，使其等于最接近的基数的倍数。\nNumber:待舍入的数值。\nSignificance:基数。\n备注:\n    当number和significance任意一个为非数值型的参数时，函数FLOOR返回错误信息*NAME?。\n    当number和significance的符号不同时，函数FLOOR返回错误信息*NUM!。\n    无论number的符号如何，舍入时参数的绝对值都将缩小。如果number恰好是指定倍数，则无需进行任何舍入处理。\n示例:\nFLOOR(2.5,-1)等于*NUM!。\nFLOOR(-2.5,-1)等于-2。\nFLOOR(2.5,2)等于2。\nFLOOR(0.143,0.03)等于0.12。";
  }

  public String getEN()
  {
    return "FLOOR(number,significance): Rounds number down, toward zero, to the nearest multiple of significance.\nNumber is the numeric value you want to round.\nSignificance is the multiple to which you want to round.\n\nRemarks:\n1. If either argument is nonnumeric, FLOOR returns the #VALUE! error value. \n2. If number and significance have different signs, FLOOR returns the #NUM! error value. \n3. Regardless of the sign of number, a value is rounded down when adjusted away from zero. If number is an exact multiple of significance, no rounding occurs. \n\nRemarks:\n   FLOOR(2.5,-1) = *NUM!\n   FLOOR(-2.5,-1) = -2\n   FLOOR(2.5,2) = 2\n   FLOOR(0.143,0.03) = 0.12";
  }
}